﻿using Meiam.System.Interfaces;
using Meiam.System.Interfaces.IService;
using Meiam.System.Model.Entity;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Meiam.System.Model.Dto;
using Microsoft.Extensions.Configuration;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using SqlSugar;
using System.Text;
using System.Data;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Meiam.System.Model;
using Microsoft.Extensions.Logging;
using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
using System.Web;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;

namespace Meiam.System.Hostd.Controllers.Gokin
{
    /// <summary>
    /// 靶向发货AI运算结果
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class BXBarcodeCheckController : ControllerBase
    {
        private readonly ILogger<BXBarcodeCheckRequestDto> _logger;
        public readonly IWMSTokenCheckService _WMSTokenCheckService;
        public readonly string con;


        public BXBarcodeCheckController(ILogger<BXBarcodeCheckRequestDto> logger,IWMSTokenCheckService wmsTokenCheckService, IConfiguration _configuration)
        {
            _logger = logger;
            _WMSTokenCheckService = wmsTokenCheckService;
             con= _configuration.GetConnectionString("DDM_DbConnection_ZH");

        }

        /// <summary>
        /// 靶向发货AI运算结果
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public IActionResult PostBXBarcodeCheck([FromBody] BXBarcodeCheckRequestDto strparm)
        {
            string  strMsg = "";
            object log = "";
            log = strparm;
            StringBuilder strSql = new StringBuilder();
            StringBuilder strSqlFine = new StringBuilder();
            List<string> strSqlList = new List<string>();
            BXBarcodeCheckResponseDto re = new BXBarcodeCheckResponseDto();
            var row = strparm.rows;
            string check_barcode_no = strparm.check_barcode_no;

            //框架查询方法
            //var data = _WMSTokenCheckService.GetTokenCheckData(supplier_code);
            int check = 0;

            try
            {
                foreach (var rows in row)
                {
                    if (rows.barcode_no == check_barcode_no)
                    {
                        check++;
                    }
                    if (check > 0)
                    {
                        strMsg = "条码<" + check_barcode_no + ">已存在请检验清楚后确认";
                    }
                    re.message = check.ToString();
                }
            }
            catch (Exception ex)
            {
                strMsg = ex.ToString();
            }

         


            if (strMsg=="")
            {
                re.status = "成功";
                re.code = "0";
            }
            else
            {
                re.status = "失败";
                re.code = "500";
                re.message = strMsg;
            }


            return new JsonResult(re);
        }

      
    }
}
